home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / SDKs / AutoPay Developer's Kit / AutoPay Devel Kit (6.90) / AutoPay™ Development / how to call AutoPay in your app / how to call AutoPay.c next >
Encoding:
C/C++ Source or Header  |  1995-10-16  |  10.4 KB  |  328 lines  |  [TEXT/MMCC]

  1. /*
  2.         File: "how to call AutoPay.c"
  3.  
  4.         Last updated 9/6/95
  5.  
  6.         This file implements a simple application demonstrating how to use
  7.         Digital Money's AutoPay™ code resource in your own application.
  8.  
  9.         This source code should run unmodified on both MetroWerks CodeWarrior C/C++
  10.         and Symantec Think C compilers. Pascal development environments are also
  11.         supported in supplementary files.
  12.  
  13.         What is this?:    This is a meaningless app that puts up a window, waits
  14.                         for you to press a button, then launches the AutoPay
  15.                         module. When the AutoPay module is finished running,
  16.                         this mini-app puts up a final window. To actually
  17.                         run this, you'll need to include the DigitalMoney.π.rsrc
  18.                         resources in your project, along with the minimal
  19.                         resource set this mini-app uses. We've thoughtfully
  20.                         included those resources in the file "how to call.π.rsrc".
  21.  
  22.         To build this project:    To build this project, include the "how to call.π.rsrc",
  23.                                 the DigitalMoney.π.rsrc file, an ANSI C library
  24.                                 (2-byte integers), and this source code file.
  25.         
  26.         Tech Support:    If you're a developer and you need technical support, we'll
  27.                         be glad to help. We also welcome your comments, suggestions,
  28.                         and gripes.
  29.  
  30.         Technical support:     (415) 833-0200
  31.                             digimoney@aol.com
  32.                             71062.1251@compuserve.com
  33.  
  34.         Sales and info:        (800) 210-5517
  35.                             Digital Money, Inc.
  36.                             Palo Alto, CA
  37. */
  38.  
  39. #include "DMIdeveloper.h.c"
  40. #include <string.h>
  41.  
  42. typedef pascal long (*DigiCodePtr) (long);
  43.  
  44. void ToolBoxInit (void);
  45. void InitDigitalMoney(digiMonBlock *myDMCB);
  46. void DoDigitalMoney(digiMonBlock *dmiBlock);
  47.  
  48. digiMonBlock    gDMCB;
  49.  
  50. /*
  51.         Function: main
  52.  
  53.         Calls InitDigitalMoney() to fill in the struct that we pass to the Digital Money
  54.         code resource. Calls DoDigitalMoney to execute the resource.
  55.  
  56.         Returns: Nothing.
  57. */
  58.  
  59. void main (void)
  60. {
  61.     
  62.     // Set the app up
  63.     ToolBoxInit();
  64.     ParamText("\pPress OK to launch the AutoPay code resource.", "\p", "\p", "\p");
  65.     NoteAlert(129, nil);
  66.  
  67.     
  68.     
  69.     // Fill in the Digital Money Control Block
  70.     InitDigitalMoney(&gDMCB);
  71.  
  72.     // Execute the code resource using our DMCB
  73.     DoDigitalMoney(&gDMCB);
  74.     
  75.     // Shut the app down
  76.     ParamText("\pCode resource finished executing.", "\p", "\p", "\p");
  77.     NoteAlert(129, nil);
  78.     ExitToShell();
  79. }
  80.  
  81. /*
  82.         Function: ToolBoxInit
  83.  
  84.         The usual suspects.
  85.  
  86.         Returns: Nothing.
  87. */
  88.  
  89. void    ToolBoxInit(void)
  90. {
  91.     InitGraf((Ptr) &qd.thePort);
  92.     InitFonts();
  93.     InitWindows();
  94.     InitMenus();
  95.     FlushEvents(everyEvent,0);
  96.     TEInit();
  97.     InitDialogs(0L);
  98.     InitCursor();
  99. }
  100.  
  101. /*
  102.         Function: InitDigitalMoney
  103.  
  104.         Fills in the digiMonBlock struct with info appropriate for our sample product.
  105.         Although this sample app doesn't do it, be sure to deallocate any memory allocated
  106.         by this function after your call to DoDigitalMoney().
  107.  
  108.         Returns: Filled in struct in the myDMCB parameter
  109. */
  110.  
  111. void InitDigitalMoney(digiMonBlock *myDMCB)
  112. {
  113.     short i;
  114.     
  115.     // General settings
  116.     
  117.     strcpy(myDMCB->programName, "Testbed 1.0");
  118.     myDMCB->returnSerialNum = 1;                         // 1=true; 0=false
  119.     myDMCB->areAdditionalItemsForSale = 1;                    // 1=true; 0=false
  120.     strcpy(myDMCB->programPassword, "tempPassword");
  121.     strcpy(myDMCB->programID, "123456");
  122.     strcpy(myDMCB->programSource, "CIS");
  123.     
  124.  
  125.     // Security
  126.     
  127.     // This is a secret string of ascii characters used for encryption.
  128.     // You should keep this key confidential, even among your own employees.
  129.     // The string is comprised of visible ASCII characters - i.e. don't
  130.     // use control characters. But punctuation is okay.
  131.     
  132.     strcpy(myDMCB->encodeMeth, "sampleEncodeUseYourOwn");
  133.  
  134.     // Screen Text
  135.     
  136.     // You can alter the text that appears on the top of each dialog box displayed
  137.     // by Digital Money. Normally, Digital Money reads "styled text" resources
  138.     // from your resource file, but if you want to change the text on the fly, so
  139.     // to speak, you can just pass a pointer leading to the appropriate
  140.     // text and style handle. Note that you must first initialize all 10 text pointers
  141.     // to zero so that Digital Money can tell the difference between a zero pointer
  142.     // (i.e. you don't want to replace the default text in the resource file) and a
  143.     // non-zero pointer (you *do* want to change the text). See below for an example.
  144.     
  145.     for (i=0; i<=9; i++) {
  146.         myDMCB->screenText[i] = 0;
  147.     }
  148.     
  149.     // Next be sure to allocate memory for any pointer that you want Digital Money
  150.     // to use. For instance, to change the text that appears on the opening screen,
  151.     // set the screenText[0] pointer, like this:
  152.     
  153.     
  154.     myDMCB->screenText[0] = NewPtr(200);
  155.     myDMCB->screenText[0] = "Digital Money is embedded in a test application.\r
  156.                             Below, select how you want to pay.";
  157.     myDMCB->textSize[0] = 10;
  158.     myDMCB->textFont[0] = applFont;
  159.     
  160.     
  161.     // ...for a complete list of which array item corresponds to which dialog,
  162.     // see printed docs.
  163.     
  164.     // The users name
  165.     
  166.     // If you already know the users name for some reason, you should send it
  167.     // to the DM Module, so that DM doesn't have to ask the user for it. If you
  168.     // don't know it, then **be sure** to set the usersName string to null. In
  169.     // any case, if the user successfully completes enough of the DM transaction,
  170.     // his name will be returned to you in this string, should you want to use it,
  171.     // for registration splash screens or whatever.
  172.     
  173.     strcpy(myDMCB->usersName, "");     // I don't know it, so it to null!
  174.     
  175.  
  176.     // Software "switches"
  177.  
  178.     // AutoPay is continually being upgraded to add new features. You can turn new
  179.     // features on and off by using a series of software "switches", which are set
  180.     // through the "privateKey" field. The format of this field is: the asterisk
  181.     // character ('*') followed by a series of 1's and 0's representing whether a
  182.     // a switch (and thus a particular feature) is turned on or off. Currently you
  183.     // can access two software switches, but six more are slated for future use.
  184.     //
  185.     // The format is:
  186.     //
  187.     //     Character    Description
  188.     //  =========    ===========
  189.     //        0        always "*"
  190.     //        1        0 = voice telephone ordering is selectable by the user
  191.     //                1 = voice telephone ordering is disabled
  192.     //        2        0 = no long product descriptions are avaiable
  193.     //                1 = long product descriptions are avaiable starting at
  194.     //                    TEXT resource 3040 (description of catalogItem[0])...
  195.     //        3=8        For future use.
  196.  
  197.     strcpy(myDMCB->privateKey, "*00000000");
  198.  
  199.     
  200.     // Your Product Catalog
  201.  
  202.     // Product names are generally short.
  203.     // If you want to include "long" product descriptions, use the software switch
  204.     // below and be sure to include one TEXT resource for every product in your
  205.     // catalog, starting with resource #3040 (for catalogItem[0]). See the Manual
  206.     // Addendum for more info.    
  207.  
  208.     myDMCB->numItemsInCatalog = 3;
  209.  
  210.      // first, initialize pointers for each item in catalog
  211.      // notice first item is item #0
  212.  
  213.      for (i= 0; i <= myDMCB->numItemsInCatalog - 1; i++)      {
  214.          myDMCB->catalogItem[i] = (catalogItemType *)NewPtr(sizeof(catalogItemType));
  215.      }
  216.      
  217.  
  218.      strcpy(myDMCB->catalogItem[0]->name, "Register Testbed 1.0");
  219.     // registration items (if the item to be bought is the actual program in
  220.     // which AutoPay is embedded), have product codes that start with 9
  221.     strcpy(myDMCB->catalogItem[0]->prodCode, "90001"); 
  222.     myDMCB->catalogItem[0]->minPurchase = 1;
  223.     myDMCB->catalogItem[0]->maxPurchase = 1;
  224.     myDMCB->catalogItem[0]->price = 15.50;
  225.     myDMCB->catalogItem[0]->numVarCodes = 0;
  226.     // Notice how you have to set shipping and handling charges (both domestic
  227.     // and foreign) even if they're zero!
  228.     myDMCB->catalogItem[0]->shUSA = 0;
  229.     myDMCB->catalogItem[0]->shFOR = 0;
  230.     
  231.      strcpy(myDMCB->catalogItem[1]->name, "Digital Money tee-shirt");
  232.     // physical goods that need to be delivered to the purchaser have product codes
  233.     // that start with 7
  234.     strcpy(myDMCB->catalogItem[1]->prodCode, "70002");
  235.     myDMCB->catalogItem[1]->minPurchase = 1;
  236.     myDMCB->catalogItem[1]->maxPurchase = 10;
  237.     myDMCB->catalogItem[1]->price = 20;
  238.     myDMCB->catalogItem[1]->numVarCodes = 2;
  239.     strcpy(myDMCB->catalogItem[1]->varCode1, "LARGE");
  240.     strcpy(myDMCB->catalogItem[1]->varCode2, "X-LARGE");
  241.     myDMCB->catalogItem[1]->shUSA = 4;
  242.     myDMCB->catalogItem[1]->shFOR = 10.50;
  243.     
  244.     strcpy(myDMCB->catalogItem[2]->name, "Upgrade from Testbed 0.9");
  245.     // software upgrades have product codes that start with 8
  246.     strcpy(myDMCB->catalogItem[2]->prodCode, "80003");
  247.     myDMCB->catalogItem[2]->minPurchase = 1;
  248.     myDMCB->catalogItem[2]->maxPurchase = 1;
  249.     myDMCB->catalogItem[2]->price = 5;
  250.     myDMCB->catalogItem[2]->numVarCodes = 0;
  251.     myDMCB->catalogItem[2]->shUSA = 0;
  252.     myDMCB->catalogItem[2]->shFOR = 0;
  253.     
  254.     
  255.     // preselect items to be purchased
  256.     // explanation: when the Digital Money module takes control of
  257.     // the user interface, what items do you want to be preselected 
  258.     // for purchase by the user? If nothing, then set the following to 0.
  259.  
  260.     myDMCB->numItemsPrepurchased = 1;
  261.     
  262.     // Notice how the data structure of the preselected item precisely matches
  263.     // the associated item in the product catalog. Please be careful and do
  264.     // the same!
  265.     
  266.     // The only exception is the "editable" flag, which can be set to false
  267.     // on a pre-selected item, even if the catalog doesn't match this. This 
  268.     // means the user won't be able to remove or edit this preselected item.
  269.     
  270.     strcpy(myDMCB->prepurchaseItem[0].name, "Register Testbed 1.0");
  271.     strcpy(myDMCB->prepurchaseItem[0].prodCode, "90001");
  272.     strcpy(myDMCB->prepurchaseItem[0].varCode, "");
  273.     myDMCB->prepurchaseItem[0].price = 15.50;
  274.     myDMCB->prepurchaseItem[0].quantity = 1;
  275.     myDMCB->prepurchaseItem[0].editable = 1;            // 1=true; 0=false
  276.     myDMCB->prepurchaseItem[0].minPurchase = 1;
  277.     myDMCB->prepurchaseItem[0].maxPurchase = 1;
  278.     myDMCB->prepurchaseItem[0].shUSA=0;
  279.     myDMCB->prepurchaseItem[0].shFOR=0;
  280.     
  281. }
  282.  
  283. /*
  284.         Function: DoDigitalMoney
  285.  
  286.         Loads the DigitalMoney code resource into memory, and executes it. This works
  287.         for PowerPC or 68K apps.
  288.  
  289.         Returns: Nothing
  290. */
  291.  
  292. void DoDigitalMoney(digiMonBlock *dmiBlock)
  293. {
  294.     UniversalProcPtr    resProcUPP;
  295.     ProcInfoType        theProcInfo;
  296.     Handle                resHandle;
  297.     OSErr                result;
  298.  
  299.     resHandle = Get1Resource('CODE', 60);
  300.     HLockHi(resHandle);
  301.  
  302. #if defined(powerc) || defined (__powerc) || GENERATINGPOWERPC
  303.  
  304.     /*
  305.         For PowerPC machines: The AutoPay resource is 68K, so if we're
  306.         generating a PowerMac app call it from the Mixed Mode Manager
  307.     */
  308.     theProcInfo = kPascalStackBased | STACK_ROUTINE_PARAMETER
  309.       (1, SIZE_CODE(sizeof(long)));
  310.     resProcUPP = NewRoutineDescriptor((ProcPtr)*resHandle,
  311.       theProcInfo, kM68kISA);
  312.     CallUniversalProc(resProcUPP, theProcInfo, (long)dmiBlock);
  313.     DisposeRoutineDescriptor(resProcUPP);
  314.     
  315. #else
  316.  
  317.     /*
  318.         For 68K machines, call it the old fashioned way
  319.     */    
  320.     ((DigiCodePtr) *resHandle) ((long) dmiBlock);
  321.     
  322.  
  323. #endif
  324.  
  325.     HUnlock(resHandle);
  326.     ReleaseResource(resHandle);
  327. }
  328.